package minStream;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;

public class StreamMinExample01 {
    static class Person {
        String name;
        int age;

        Person(String name, int age) {
            this.name = name;
            this.age = age;
        }

        int getAge() {
            return age;
        }

        @Override
        public String toString() {
            return name + ": " + age;
        }
    }

    public static void main(String[] args) {
        List<Person> people = Arrays.asList(
                new Person("Alice", 22),
                new Person("Bob", 20),
                new Person("Charlie", 30),
                new Person("David", 25)
        );


        Optional<Person> youngest = people.stream().min((p1, p2) -> Integer.compare(p1.getAge(), p2.getAge()));


        youngest.ifPresent(person -> System.out.println("The youngest person is " + person));
    }
}
